package com.controller;



import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.common.utils.base.UuidUtil;
import com.entity.YongHuHangYe;
import com.service.YongHuHangYeService;

@Controller
@RequestMapping("/yonghuhangye/manager")
public class YongHuHangYeController {

	@Autowired
	private YongHuHangYeService yhhyService;


	@RequestMapping("/table")
	public String table(Model md,String id){
		return "pages/tables";
	}
	@RequestMapping("/findByPage")
	@ResponseBody
	public AjaxRes findByPage(YongHuHangYe yh,Page<YongHuHangYe> page){
		AjaxRes res = new AjaxRes();
		page = yhhyService.findByPage(yh, page);
		res.setSucceed(page,"成功");
		return res;
	}
	@RequestMapping("/addyhhy")
	@ResponseBody
	public AjaxRes addyhhy(YongHuHangYe yh){
		String Id=UuidUtil.get32UUID();
		yh.setId(Id);
		AjaxRes res = new AjaxRes();
		yhhyService.insert(yh);
		res.setResMsg("成功");
		return res;
	}
	@RequestMapping("/delyhhy")
	@ResponseBody
	public AjaxRes delyhhy(YongHuHangYe yh){
		AjaxRes res = new AjaxRes();
		yhhyService.delete(yh);
		res.setSucceedMsg("删除成功");
		return res;
	}
	
	@RequestMapping("/delAllyhhy")
	@ResponseBody
	public AjaxRes delAllyhhy(String cks){
		AjaxRes res = new AjaxRes(); 
		String[] ck = cks.split(",");
		List<YongHuHangYe> list = new ArrayList<YongHuHangYe>();
		for(String s:ck){
			YongHuHangYe yh = new YongHuHangYe();
			yh.setId(s);
			list.add(yh);
		}
		yhhyService.deleteBatch(list);
		res.setSucceedMsg("删除成功");
		return res;
	}

	
	@RequestMapping("/updateyhhy")
	@ResponseBody
	public AjaxRes updateyhhy(YongHuHangYe yh){
		AjaxRes res = new AjaxRes();
		yhhyService.update(yh);
		res.setSucceedMsg("修改成功");
		return res;
	}

	@RequestMapping("/find")
	@ResponseBody
	public AjaxRes find(YongHuHangYe yh){
		AjaxRes res = new AjaxRes();
		List<YongHuHangYe> yhhyList = yhhyService.find(yh);
		res.setSucceed(yhhyList,"获取数据成功");
		return res;
	}
	
}
